package com.issac.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitTopicConfig {
    public static final String TOPICNAME = "issac_topic";

    @Bean
    Queue queueXiaomi(){
        return new Queue("xiaomi");
    }

    @Bean
    Queue queueHuawei(){
        return new Queue("huawei");
    }

    @Bean
    Queue queuePhone(){
        return new Queue("phone");
    }

    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange(TOPICNAME,true,false);
    }

    @Bean
    Binding bindingXiaomi(){
        return BindingBuilder.bind(queueXiaomi()).to(topicExchange()).with("xiaomi.#");
    }

    @Bean
    Binding bindingHuawei(){
        return BindingBuilder.bind(queueHuawei()).to(topicExchange()).with("huawei.#");
    }

    @Bean
    Binding bindingPhone(){
        return BindingBuilder.bind(queuePhone()).to(topicExchange()).with("#.phone.#");
    }
}
